home *** CD-ROM | disk | FTP | other *** search
- // (C) Copyright Microsoft Corp. 1991. All rights reserved.
- //
- // You have a royalty-free right to use, modify, reproduce and
- // distribute the Sample Files (and/or any modified version) in
- // any way you find useful, provided that you agree that
- // Microsoft has no warranty obligations or liability for any
- // Sample Application Files which are modified.
-
- /****************************************************************************
-
- MODULE : mci.c
-
- PURPOSE : Module which contains the MCI functionality of the playvfw application. All Video for
- Windows as well as audio calls are contained in this module.
-
- FUNCTIONS :
-
- OpenVFWDevice
- OpenVFWFile
- PlayVFWFile
- PlayVFWFileWait
- CloseVFWFile
- CloseAllDevices
- SeekVFWToStart
- StepVFW
- StepVFWReverse
- UpdateVFW
- PauseVFWFile
- StopVFWFile
- ResumeVFWFile
- CloseVFWDevice
- OpenPlayCloseVFW
- SndPlaySnd
- ErrorProc
- OpenWaveDevice
- PlayWaveFile
- StopWaveFile
- CloseWaveFile
- CloseWaveDevice
- cNumAudio
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
- #include <windows.h>
- #include <stdio.h>
- #include <mmsystem.h>
- #include <digitalv.h>
- #include "playvfw.h"
- #include "proto.h"
-
-
- // forward declarations
-
- /****************************************************************************
-
- FUNCTION : OpeVFWDevice(HWND)
-
- PURPOSE : This function opens the device avivideo and leaves it open.
-
-
- mciopen.lpstrDeviceType="avivideo"
-
- Using this format you only have to specify
-
- MCI_OPEN_TYPE for dwflags.
-
- COMMENTS : Opening the driver once and leaving it open saves time.
- You can then use this driver ID in the following calls
- to open elements (AVI videos). This saves time since if
- you open an element without specifying an open device ID
- mci must open the driver and close the driver each time.
- When playing multiple elements (AVI videos) this excess time
- can be costly. Therefore to conserve time you should open
- the avivideo device, play the AVI videos, close the avivideo
- device.
-
-
- HISTORY :
-
- ****************************************************************************/
-
-
- WORD FAR PASCAL OpenVFWDevice(hWnd)
-
- HWND hWnd;
- {
-
- MCI_DGV_OPEN_PARMS mciopen;
- DWORD dwRes;
- WORD wGlobalDeviceID;
- DWORD dwFlags;
- HANDLE hMem;
- LPSTR lpMem;
-
- // no device ID is necessary when opening using DeviceType.
- hMem=GlobalAlloc(GHND,80);
- lpMem=GlobalLock(hMem);
- lstrcpy(lpMem,(LPSTR)"avivideo");
-
- mciopen.wDeviceID=0;
- //mciopen.lpstrDeviceType=(LPSTR)"avivideo";
- mciopen.lpstrDeviceType=lpMem;
- //mciopen.lpstrAlias=(LPSTR)"";
-
- // Set the device to be shareable so that several AVI videos can be open at a single time.
- // MCI_OPEN_TYPE specifies that the lpstrDeviceType string is to be used to specify what device
- // is to be open.
-
- dwFlags= MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE;
-
- // Send the command to open the device. dwRes returns an error number if the command fails otherwise
- // it returns 0.
-
-
- dwRes=mciSendCommand(0,MCI_OPEN,dwFlags,(DWORD)(LPSTR)&mciopen);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return(FALSE);
- }
-
- GlobalUnlock(hMem);
- GlobalFree(hMem);
-
- // retrieve the device ID from the mciopen structure.
- wGlobalDeviceID=mciopen.wDeviceID;
-
- return(wGlobalDeviceID);
- }
-
-
- /****************************************************************************
-
- FUNCTION : OpenVFWFile(HWND,DWORD,LPSTR,LPSTR)
-
- PURPOSE : This function takes a currently open device ID, a
- string representing a AVI video, a handle to a window which could
- be omitted since it is not used and opens that AVI Video.
-
-
- COMMENTS : This function is used to open a AVI video for later playback. The function returns
- a device ID which can be used later to playback the video.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- WORD FAR PASCAL OpenVFWFile(hWnd,wGlobalDeviceID,lpVFWName,lpVFWAlias)
-
- HWND hWnd;
- WORD wGlobalDeviceID;
- LPSTR lpVFWName;
- LPSTR lpVFWAlias;
- {
-
- MCI_DGV_OPEN_PARMS mciopen;
- DWORD dwRes;
- DWORD dwFlags;
- //MCI_DGV_WINDOW_PARMS mciWindow;
-
-
-
- // Set the flags so that we open an element, AVI video, and use an alias. By using an alias
- // we avoid colliding with other attempts to open the same video.
-
-
- dwFlags= MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS;
-
- mciopen.lpstrElementName=(LPSTR)lpVFWName;
-
-
-
- mciopen.lpstrDeviceType=NULL;
- mciopen.lpstrAlias=lpVFWAlias;
-
- // Send the command to open the device. dwRes returns an error number if the command fails otherwise
- // it returns 0.
-
- dwRes=mciSendCommand(wGlobalDeviceID,MCI_OPEN,dwFlags,(DWORD)(LPSTR)&mciopen);
-
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
-
- return mciopen.wDeviceID;
- }
-
- /****************************************************************************
-
- FUNCTION : PlayVFWFile(HWND,HWND,DWORD)
-
- PURPOSE : This function takes a currently open device ID, a handle to a window
- that will be notified when playback is finished and a handle to a Window the
- AVI file will play in and calls the MCI_PLAY command. The function immediately
- returns and does not wait for the AVI file to finish playing.
-
- COMMENTS : dwFlags is set to MCI_DGV_WINDOW_HWND so that the function will play the video
- in a window specified by the handle passed to the function. hWnd1 is the handle to the
- window in which you will be playing the video into. Specifying a seperate window to play
- the video in must be done before the play command. hWnd is the callback window which will
- be notified once the video is finished playing.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL PlayVFWFile(hWnd,hWnd1,wDeviceID)
-
- HWND hWnd;
- HWND hWnd1;
- WORD wDeviceID;
-
- {
-
- MCI_DGV_PLAY_PARMS mciplay;
- DWORD dwRes;
- DWORD dwFlags;
- MCI_DGV_WINDOW_PARMS mciWindow;
-
- if (!wDeviceID)
- return FALSE;
-
- // specify the HWND which the video should be played into.
-
- mciWindow.hWnd=hWnd1;
-
- // Send a command to AVI specifying that the playback window will be defined by the HWND
- // passed.
-
- dwRes=mciSendCommand(wDeviceID,MCI_WINDOW,MCI_DGV_WINDOW_HWND,(DWORD)(LPSTR)&mciWindow);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- mciplay.dwFrom=0;
-
- // use a callback window specified by the hWnd paramater.
-
- mciplay.dwCallback = MAKELONG(hWnd,0);
-
-
- dwFlags=MCI_NOTIFY;
-
- dwRes=mciSendCommand(wDeviceID,MCI_PLAY,dwFlags,(DWORD)(LPSTR)&mciplay);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
-
- return TRUE;
- }
-
- /****************************************************************************
-
- FUNCTION : PlayVFWFile(HWND,HWND,DWORD)
-
- PURPOSE : This function takes a currently open device ID, a handle to a window
- that will be notified when playback is finished and a handle to a Window the
- AVI file will play in and calls the MCI_PLAY command. The function immediately
- returns and does not wait for the AVI file to finish playing.
-
- COMMENTS : dwFlags is set to MCI_DGV_WINDOW_HWND so that the function will play the video
- in a window specified by the handle passed to the function. hWnd1 is the handle to the
- window in which you will be playing the video into. Specifying a seperate window to play
- the video in must be done before the play command. hWnd is the callback window which will
- be notified once the video is finished playing. Since the MCI_WAIT flag is being used the
- hWnd paramater is unecessary.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL PlayVFWFileWait(hWnd,hWnd1,wDeviceID)
-
- HWND hWnd;
- HWND hWnd1;
- WORD wDeviceID;
-
- {
-
- MCI_DGV_PLAY_PARMS mciplay;
- DWORD dwRes;
- DWORD dwFlags;
- MCI_DGV_WINDOW_PARMS mciWindow;
-
-
- if (!wDeviceID)
- return FALSE;
-
- // specify the HWND which the video should be played into.
- mciWindow.hWnd=hWnd1;
-
- // Send a command to AVI specifying that the playback window will be defined by the HWND
- // passed.
-
- dwRes=mciSendCommand(wDeviceID,MCI_WINDOW,MCI_DGV_WINDOW_HWND,(DWORD)(LPSTR)&mciWindow);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- mciplay.dwFrom=0;
-
- // set the flag to wait until playback is finished before allowing mciSendCommand to return.
-
- dwFlags=MCI_WAIT;
-
- dwRes=mciSendCommand(wDeviceID,MCI_PLAY,dwFlags,(DWORD)(LPSTR)&mciplay);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
-
- return TRUE;
- }
-
- /****************************************************************************
-
- FUNCTION : CloseVFWFile(HWND,WORD,LPSTR)
-
- PURPOSE : This function takes a currently open device ID and closes the device
- element (AVI file).
-
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL CloseVFWFile(wDeviceID)
-
- WORD wDeviceID;
- {
-
- DWORD dwRes;
-
- if (!wDeviceID)
- return FALSE;
-
- dwRes=mciSendCommand(wDeviceID,MCI_CLOSE,0,NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- return TRUE;
- }
-
-
- /****************************************************************************
-
- FUNCTION : CloseAllDevices()
-
- PURPOSE : This function closes all currently open devices for the application.
-
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
- BOOL FAR PASCAL CloseAllDevices()
-
-
- {
- DWORD dwRes;
-
-
-
-
- // Close the global device
-
-
-
- dwRes=mciSendCommand(MCI_ALL_DEVICE_ID,MCI_CLOSE,0,NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return(FALSE);
- }
-
-
-
- return(TRUE);
- }
-
-
-
- /****************************************************************************
-
- FUNCTION : SeekVFWFile(WORD)
-
- PURPOSE : This function takes a currently open device ID and seeks
- to the start of the AVI file.
-
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL SeekVFWToStart(wDeviceID)
- WORD wDeviceID;
- {
- DWORD dwRes;
-
- if (!wDeviceID)
- return FALSE;
-
- dwRes=mciSendCommand(wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- return TRUE;
- }
-
- /****************************************************************************
-
- FUNCTION : StepVFW(WORD)
-
- PURPOSE : This function takes a currently open device ID and steps the AVI file
- to the frame specified by nFrames.
-
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL StepVFW(wDeviceID,nFrames)
- WORD wDeviceID;
- int nFrames;
- {
- DWORD dwRes;
- MCI_DGV_STEP_PARMS mciStep;
-
- if (!wDeviceID)
- return FALSE;
-
- mciStep.dwFrames=nFrames;
-
- // This functions will return error codes when you step past the end of the Video. To avoid
- // the constant error messages recieved I chose to not return the string provided by mciErrorString.
-
- dwRes=mciSendCommand(wDeviceID, MCI_STEP, MCI_DGV_STEP_FRAMES, (DWORD)(LPSTR)&mciStep);
-
- if (dwRes)
- {
- return FALSE;
- }
-
- return TRUE;
- }
-
- /****************************************************************************
-
- FUNCTION : StepVFWReverse(WORD)
-
- PURPOSE : This function takes a currently open device ID and steps the video
- back 1 frame.
-
- COMMENTS : Since you cannot specify how many frames in reverse you would like
- to step I left off the nFrames parameter.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL StepVFWReverse(wDeviceID)
- WORD wDeviceID;
-
- {
- DWORD dwRes;
- //MCI_DGV_STEP_PARMS mciStep;
-
- if (!wDeviceID)
- return FALSE;
-
- dwRes=mciSendCommand(wDeviceID, MCI_STEP, MCI_DGV_STEP_REVERSE, (DWORD)(LPVOID)NULL);
-
- if (dwRes)
- {
- return FALSE;
- }
-
- return TRUE;
- }
-
- /****************************************************************************
-
- FUNCTION : UpdateVFW(WORD, HDC)
-
- PURPOSE : This function takes a currently open device ID and
- a handle to a device context refreshing the current frame in the window.
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL UpdateVFW(wDeviceID,hDC)
- WORD wDeviceID;
- HDC hDC;
- {
- DWORD dwRes;
- MCI_DGV_UPDATE_PARMS mciUpdate;
-
- if (!wDeviceID)
- return FALSE;
-
- mciUpdate.hDC=hDC;
-
- dwRes=mciSendCommand(wDeviceID, MCI_UPDATE, MCI_DGV_UPDATE_HDC, (DWORD)(LPMCI_DGV_UPDATE_PARMS)&mciUpdate);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- return TRUE;
- }
-
-
- /****************************************************************************
-
- FUNCTION : PauseVFWFile(WORD)
-
- PURPOSE : This function takes a currently open device ID and Pauses the
- AVI file at the current frame.
-
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL PauseVFWFile(wDeviceID)
- WORD wDeviceID;
- {
- DWORD dwRes;
-
- if (!wDeviceID)
- return FALSE;
-
- dwRes=mciSendCommand(wDeviceID, MCI_PAUSE, 0, (DWORD)(LPVOID)NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- return TRUE;
- }
-
-
- /****************************************************************************
-
- FUNCTION : StopVFWFile(HWND,WORD,LPSTR)
-
- PURPOSE : This function takes a currently open device ID and stops the AVI file
- on the current frame.
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL StopVFWFile(wDeviceID)
- WORD wDeviceID;
- {
- DWORD dwRes;
-
- if (!wDeviceID)
- return FALSE;
-
- dwRes=mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD)(LPVOID)NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- return TRUE;
- }
-
- /****************************************************************************
-
- FUNCTION : ResumeVFWFile(HWND,WORD,LPSTR)
-
- PURPOSE : This function takes a currently open device ID and resumes the AVI file
- where it left off.
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL ResumeVFWFile(wDeviceID)
- WORD wDeviceID;
- {
- DWORD dwRes;
-
- if (!wDeviceID)
- return FALSE;
-
- dwRes=mciSendCommand(wDeviceID, MCI_RESUME, 0, (DWORD)(LPVOID)NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- return TRUE;
- }
-
-
-
- /****************************************************************************
-
- FUNCTION : CloseVFWDevice(HWND,WORD)
-
- PURPOSE : This function closes a currently open AVI device.
-
-
- COMMENTS : To conserve system resources you should always close a
- device when you are not using it.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL CloseVFWDevice(hWnd,wGlobalDeviceID)
-
- HWND hWnd;
- WORD wGlobalDeviceID;
-
- {
- DWORD dwRes;
-
- if (!wGlobalDeviceID)
- return FALSE;
- // Close the global device
-
- dwRes=mciSendCommand(wGlobalDeviceID,MCI_CLOSE,0,NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return(FALSE);
- }
-
-
-
- return(TRUE);
- }
-
-
-
- /****************************************************************************
-
- FUNCTION : OpenPlayCloseVFW(HWND,HWND,LPSTR)
-
- PURPOSE : This function demonstrates how to open an element (avifile)
- play the AVI video and close that element in one fell swoop.
-
- COMMENTS : Rather than opening the global device "avivideo" before
- playing the AVI file we let MCI do this for us. After playing
- the element we immediately close the element and MCI closes
- the global device "avivideo" for you. Unfortunately doing
- this is slow and is not advisable if you will be playing several
- AVI files at a time. If you plan on playing several AVI files
- at a time it is advisable for speed to use the previously
- demonstrated method. Which is opening the global avivideo device.
- Leaving that device open and passing it to the open for the element
- (avifile). Playing all the avifiles and then closing the global
- avivideo device when you are finished.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL OpenPlayCloseVFW(hWnd,hWnd1,lpVFWfile)
-
- HWND hWnd;
- HWND hWnd1;
- LPSTR lpVFWfile;
-
-
- {
- MCI_DGV_OPEN_PARMS mciopen;
- MCI_PLAY_PARMS mciplay;
- DWORD dwRes;
- WORD wDeviceID;
- //WORD wGlobalDeviceID;
- DWORD dwFlags;
- MCI_DGV_WINDOW_PARMS mciWindow;
-
-
-
-
- mciopen.lpstrDeviceType=(LPSTR)"avivideo";
- mciopen.lpstrElementName=(LPSTR)lpVFWfile;
-
-
- dwFlags=MCI_OPEN_TYPE | MCI_OPEN_ELEMENT;
-
-
-
- dwRes=mciSendCommand(0,MCI_OPEN,dwFlags,(DWORD)(LPSTR)&mciopen);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- wDeviceID=mciopen.wDeviceID;
-
- mciWindow.hWnd=hWnd1;
- dwRes=mciSendCommand(wDeviceID,MCI_WINDOW,MCI_DGV_WINDOW_HWND,(DWORD)(LPSTR)&mciWindow);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
-
- mciplay.dwFrom=0;
- dwFlags=MCI_WAIT | MCI_FROM;
- dwRes=mciSendCommand(wDeviceID,MCI_PLAY,dwFlags,(DWORD)(LPSTR)&mciplay);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- mciSendCommand(wDeviceID,MCI_CLOSE,0L,NULL);
-
- return TRUE;
- }
-
-
- /****************************************************************************
-
- FUNCTION : SndPlaySnd(HWND,LPSTR)
-
- PURPOSE : This function demonstrates how to use the function
- sndPlaySound. This is the easiest way to play a wave file.
-
- COMMENTS : The one setback to using sndPlaySound is that the entire
- sound is loaded into memory at once. If you have a very
- large sound sndPlaySound will fail if the sound will not
- load into physical memory.
-
- HISTORY :
-
- ****************************************************************************/
-
- BOOL FAR PASCAL SndPlaySnd(hWnd,lpWavefile)
-
- HWND hWnd;
- LPSTR lpWavefile;
-
-
- {
- WORD wFlags;
-
-
-
- MessageBox(NULL,lpWavefile,(LPSTR)"Playing Sound File",MB_OK);
-
-
- wFlags=SND_ASYNC;
-
- if (sndPlaySound(lpWavefile,wFlags))
- return(TRUE);
- else
- return(FALSE);
-
- }
-
-
- /****************************************************************************
-
- FUNCTION : ErrorProc(WORD)
-
- PURPOSE : ErrorProc calls mciGetErrorString to display an error
- message returned by MCI.
-
- COMMENTS :
-
- HISTORY :
-
- ****************************************************************************/
-
- void FAR PASCAL ErrorProc(dwResult)
-
- DWORD dwResult;
-
- {
- HANDLE hMem;
- LPSTR lpStringBuff;
-
-
- hMem=GlobalAlloc(GHND,80);
-
- if (hMem)
- {
- lpStringBuff=GlobalLock(hMem);
- if (lpStringBuff)
- {
- if(mciGetErrorString(dwResult,lpStringBuff,80))
- MessageBox(NULL,lpStringBuff,"ERROR",MB_OK);
- else
- MessageBox(NULL,"Generic Error","ERROR",MB_OK);
-
- GlobalUnlock(hMem);
- }
- else
- MessageBox(NULL,"Lock Failed","ERROR",MB_OK);
-
- GlobalFree(hMem);
- }
- else
- MessageBox(NULL,"Alloc Failed","ERROR",MB_OK);
-
- return;
- }
-
-
-
- /****************************************************************************
-
- FUNCTION : OpenWaveDevice(HWND)
-
- PURPOSE : This function opens the device waveaudio and leaves it open.
- The device could also be opened by assigning the string
- "waveaudio" as follows.
-
- mciopen.lpstrDeviceType="waveaudio"
-
- Using this format you would only have to specify
-
- MCI_OPEN_TYPE for dwflags.
-
- COMMENTS : Opening the driver once and leaving it open saves time.
- You can then use this driver ID in the following calls
- to open elements (wavefiles). This saves time since if
- you open an element without specifying an open device ID
- mci must open the driver and close the driver each time.
- When playing multiple elements (wavefiles) this excess time
- can be costly. Therefore to conserve time you should open
- the waveaudio device, play the waves, close the waveaudio
- device.
-
-
- HISTORY :
-
- ****************************************************************************/
-
-
- WORD FAR PASCAL OpenWaveDevice(void)
-
- {
-
- MCI_OPEN_PARMS mciopen;
- DWORD dwRes;
- WORD wGlobalDeviceID;
- DWORD dwFlags;
-
-
- mciopen.wDeviceID=0;
- mciopen.lpstrDeviceType=(LPSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
-
-
- // when specifying the device ID you must also include the
- //MCI_OPEN_TYPE flag.
-
-
- dwFlags= MCI_OPEN_TYPE_ID | MCI_OPEN_TYPE;
-
- dwRes=mciSendCommand(0,MCI_OPEN,dwFlags,(DWORD)(LPSTR)&mciopen);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return(FALSE);
- }
-
- wGlobalDeviceID=mciopen.wDeviceID;
-
- return(wGlobalDeviceID);
- }
-
-
- /****************************************************************************
-
- FUNCTION : OpenWaveFile(HWND,WORD,LPSTR)
-
- PURPOSE : This function takes a currently open device ID and a
- string representing a wave file and plays that wavefile.
- When the wavefile is finished playing the function closes
- the wavefile.
-
- COMMENTS : dwFlags is set to MCI_WAIT so that the function will not
- return until the wavefile is done playing. If you want
- the function to return before the wavefile is finished
- playing omit the MCI_WAIT flag.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- WORD FAR PASCAL OpenWaveFile(wGlobalDeviceID,lpWaveName,lpAlias)
-
- WORD wGlobalDeviceID;
- LPSTR lpWaveName;
- LPSTR lpAlias;
- {
-
- MCI_OPEN_PARMS mciopen;
- //MCI_PLAY_PARMS mciplay;
- DWORD dwRes;
- WORD wDeviceID;
- DWORD dwFlags;
- //char szWaveMessage[80];
-
-
-
- if (!wGlobalDeviceID)
- return FALSE;
-
-
- // Open the wave file independent of the device. This will speed up
- // the playing of the wavefile.
-
-
-
-
- dwFlags= MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS;
-
- mciopen.lpstrElementName=(LPSTR)lpWaveName;
-
- // All strings must be initialized otherwise this will crash under
- // the debug version of mmsystem.
-
- mciopen.lpstrDeviceType="\0";
- mciopen.lpstrAlias=(LPSTR)lpAlias;
-
- dwRes=mciSendCommand(wGlobalDeviceID,MCI_OPEN,dwFlags,(DWORD)(LPSTR)&mciopen);
-
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- // play the wave file.
-
- wDeviceID=mciopen.wDeviceID;
-
-
- return wDeviceID;
- }
-
-
-
-
- /****************************************************************************
-
- FUNCTION : PlayWave(HWND,WORD,LPSTR)
-
- PURPOSE : This function takes a currently open device ID and a
- string representing a wave file and plays that wavefile.
- When the wavefile is finished playing the function closes
- the wavefile.
-
- COMMENTS : dwFlags is set to MCI_WAIT so that the function will not
- return until the wavefile is done playing. If you want
- the function to return before the wavefile is finished
- playing omit the MCI_WAIT flag.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL PlayWaveFile(wDeviceID)
-
- WORD wDeviceID;
-
- {
-
- //MCI_OPEN_PARMS mciopen;
- MCI_PLAY_PARMS mciplay;
- DWORD dwRes;
- DWORD dwFlags;
- //char szWaveMessage[80];
-
-
- if (!wDeviceID)
- return FALSE;
-
-
- // Open the wave file independent of the device. This will speed up
- // the playing of the wavefile.
-
-
-
- mciplay.dwFrom=0;
-
-
- dwFlags=MCI_FROM;
-
-
- dwRes=mciSendCommand(wDeviceID,MCI_PLAY,dwFlags,(DWORD)(LPSTR)&mciplay);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
-
- return TRUE;
- }
-
-
- /****************************************************************************
-
- FUNCTION : PlayWave(HWND,WORD,LPSTR)
-
- PURPOSE : This function takes a currently open device ID and a
- string representing a wave file and plays that wavefile.
- When the wavefile is finished playing the function closes
- the wavefile.
-
- COMMENTS : dwFlags is set to MCI_WAIT so that the function will not
- return until the wavefile is done playing. If you want
- the function to return before the wavefile is finished
- playing omit the MCI_WAIT flag.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL StopWaveFile(wDeviceID)
-
- WORD wDeviceID;
- {
-
-
-
- DWORD dwRes;
- DWORD dwFlags;
-
-
- if (!wDeviceID)
- return FALSE;
-
-
- // Open the wave file independent of the device. This will speed up
- // the playing of the wavefile.
-
- dwFlags=MCI_WAIT;
-
- dwRes=mciSendCommand(wDeviceID,MCI_STOP,dwFlags,(DWORD)(LPVOID)NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
-
- return TRUE;
- }
-
-
- /****************************************************************************
-
- FUNCTION : CloseWaveFile(HWND,WORD,LPSTR)
-
- PURPOSE : This function takes a currently open device ID and a
- string representing a wave file and plays that wavefile.
- When the wavefile is finished playing the function closes
- the wavefile.
-
- COMMENTS : dwFlags is set to MCI_WAIT so that the function will not
- return until the wavefile is done playing. If you want
- the function to return before the wavefile is finished
- playing omit the MCI_WAIT flag.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL CloseWaveFile(wDeviceID)
-
- WORD wDeviceID;
- {
-
- DWORD dwRes;
-
- if (!wDeviceID)
- return FALSE;
-
- // Open the wave file independent of the device. This will speed up
- // the playing of the wavefile.
-
- dwRes=mciSendCommand(wDeviceID,MCI_CLOSE,0,NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return FALSE;
- }
-
- return TRUE;
- }
-
-
- /****************************************************************************
-
- FUNCTION : CloseWaveDevice(HWND,WORD)
-
- PURPOSE : This function closes a currently open waveaudio device.
-
-
- COMMENTS : To conserve system resources you should always close a
- device when you are not using it.
-
- HISTORY :
-
- ****************************************************************************/
-
-
- BOOL FAR PASCAL CloseWaveDevice(wGlobalDeviceID)
-
- WORD wGlobalDeviceID;
-
- {
- DWORD dwRes;
-
- if (!wGlobalDeviceID)
- return FALSE;
-
- // Close the global device
-
- dwRes=mciSendCommand(wGlobalDeviceID,MCI_CLOSE,0,NULL);
-
- if (dwRes)
- {
- ErrorProc(dwRes);
- return(FALSE);
- }
-
-
-
- return(TRUE);
- }
-
- /****************************************************************************
-
- FUNCTION : cNumAudio
-
- PARAMETERS : void
-
- PURPOSE : retrieves the number of waveform output devices
- present in the system.
-
- CALLS : WINDOWS
- GetModuleHandle
- waveOutGetNumDevs
-
- RETURNS : number of wave output devices found
-
- MESSAGES : none
-
- COMMENTS : first checks to see if MMSYSTEM is loaded. So it works
- in 3.0 as well as 3.1
-
- HISTORY : 8/31/93 - Function added to playvfw by stevemo
-
- ****************************************************************************/
-
- int PASCAL cNumAudio(void)
- {
- UINT (FAR *lpfnwaveOutGetNumDevs) (void);
- HINSTANCE hInstWave;
- int nRet = 0;
- HANDLE hModule = GetModuleHandle("mmsystem.dll");
-
- if (hModule)
- {
- hInstWave = LoadLibrary("MMSYSTEM.DLL");
- if (hInstWave > HINSTANCE_ERROR)
- {
- (FARPROC) lpfnwaveOutGetNumDevs =
- GetProcAddress(hInstWave, "waveOutGetNumDevs");
- nRet = (*lpfnwaveOutGetNumDevs) ();
- FreeLibrary(hInstWave);
- }
- }
- return (nRet);
- }
-